<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="<?php echo __URL_BASE ?>js/jquery-1.8.3.min.js" type="text/javascript"></script>
<link href="<?php echo __URL_BASE ?>css/bootstrap.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
	$(document).ready(function(e) {
			
        $('#btnSignUp').click(function(e) {
            
			pass = $('#passwd').val();
			conpass= $('#conpasswd').val();
			
			if(!validatePass(pass)){
				alert('Mật khẩu phải tuân thủ quy tắc sau. \n- Ít nhất 6 ký tự. \n- Có ít nhất 1 ký tự viết hoa.\n- Có ít nhất 1 ký tự viết thường.\n- Có ít nhất 1 ký tự là số.');
				$('#passwd').select();
				return false;
			}
			
			if(pass != conpass){
				alert('Mật khẩu không khớp.');
				$("#conpasswd").select();
				return false;
			}
			
			//validate email
			emailVal = $('#email').val();
			if(!validateEmail(emailVal)){
				alert('Email không hợp lệ.');
				$("#email").select();
				return false;
			}
			
			
        });
		
		$("#mobile").keydown(function(event) {
		// Allow: backspace, delete, tab, escape, and enter
			if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || 
			
			event.keyCode == 27 || event.keyCode == 13 || 
			// Allow: Ctrl+A
			(event.keyCode == 65 && event.ctrlKey === true) || 
			// Allow: home, end, left, right
			(event.keyCode >= 35 && event.keyCode <= 39)) {
			// let it happen, don't do anything
				return;
			}
			else {
			// Ensure that it is a number and stop the keypress
				if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && 
			
				(event.keyCode < 96 || event.keyCode > 105 )) {
					event.preventDefault(); 
				}   
			}
		});
    });
	function validatePass($pass) { //it nhat 6 ky tu, co it nhat 1 ky tu viet hoa, viet thuong, 1 ky tu la so, 1 ky tu dac biet
	  var emailReg = /(?=^.{6,}$)(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[^A-Za-z0-9]).*/;
	  if( !emailReg.test( $pass ) ) {
		return false;
	  } else {
		return true;
	  }
	}
	function validateEmail($email) {
	  var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	  if( !emailReg.test( $email ) ) {
		return false;
	  } else {
		return true;
	  }
	}
	
</script>
</head>

<body>
<?php
	$hoten = (isset($user)) ? $user->HoTen : '';
	$tendangnhap = (isset($user)) ? $user->TenDangNhap : ''; //echo $tendangnhap; die;
	$email = (isset($user)) ? $user->Email : '';
	$diachi = (isset($user)) ? $user->DiaChi : '';
	$dienthoai = (isset($user)) ? $user->DienThoai : '';
	$quyen = (isset($user)) ? $user->Quyen : '';
	$trangthai = (isset($user)) ? $user->TrangThai : '';
?>
<div class="container">
<!--<legend>Sign Up</legend>-->
<div class="well">
      <form id="signup" class="form-horizontal" method="post" action="<?php echo __URL_BASE.'index.php?rt=user/registration' ?>">
        <legend>Đăng ký</legend>
        <div class="control-group">
            <label class="control-label">Tên đăng nhập</label>
            <div class="controls">
                <div class="input-prepend">
                <span class="add-on"><i class="icon-user"></i></span>
                    <input type="text" class="input-xlarge" id="username" name="username" placeholder="Nhập tên đăng nhập" required="required" autocomplete="off" value="<?php echo $tendangnhap ?>">
                </div>
            </div>
        </div>
         <div class="control-group">
            <label class="control-label">Password</label>
            <div class="controls">
                <div class="input-prepend">
                <span class="add-on"><i class="icon-lock"></i></span>
                    <input type="Password" id="passwd" class="input-xlarge" name="passwd" placeholder="Nhập mật khẩu " required="required" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">Confirm Password</label>
            <div class="controls">
                <div class="input-prepend">
                <span class="add-on"><i class="icon-lock"></i></span>
                    <input type="Password" id="conpasswd" class="input-xlarge" name="conpasswd" placeholder="Nhập lại mật khẩu" required="required">
                </div>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">Họ và tên</label>
            <div class="controls">
                <div class="input-prepend">
                <span class="add-on"><i class="icon-user"></i></span>
                    <input type="text" class="input-xlarge" id="fname" name="fname" placeholder="Nhập họ và tên" required="required" autocomplete="off" value="<?php echo $hoten ?>">
                </div>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">Email</label>
            <div class="controls">
                <div class="input-prepend">
                <span class="add-on"><i class="icon-envelope"></i></span>
                    <input type="text" class="input-xlarge" id="email" name="email" placeholder="Nhập email" required="required" autocomplete="off" value="<?php echo $email ?>">
                    
                </div>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">Điện thoại</label>
            <div class="controls">
                <div class="input-prepend">
                <span class="add-on"><i class="icon-envelope"></i></span>
                    <input type="text" class="input-xlarge" id="mobile" name="mobile" placeholder="Nhập số điện thoại" required="required" autocomplete="off" value="<?php echo $dienthoai ?>">
                </div>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">Địa chỉ</label>
            <div class="controls">
                <div class="input-prepend">
                <span class="add-on"><i class="icon-envelope"></i></span>
                    <input type="text" class="input-xlarge" id="address" name="address" placeholder="Nhập địa chỉ nhận hàng" required="required" autocomplete="off" value="<?php echo $diachi ?>">
                </div>
            </div>
        </div>
       <!-- <div class="control-group">
            <label class="control-label">Gender</label>
            <div class="controls">
                    <p><div id="gender" name="gender" class="btn-group" data-toggle="buttons-radio">
                    <button type="button" class="btn btn-info">Male</button>
                    <button type="button" class="btn btn-info">Female</button>
                  </div></p>
            </div>
        </div>-->
       
        <div class="control-group">
        <label class="control-label"></label>
          <div class="controls">
           <button id="btnSignUp" type="submit" class="btn btn-success" >Tạo tài khoản</button>
          </div>
    </div>
      </form>
   </div>
</div>
<?php if(isset($message_user))  echo "<script>alert('".$message_user."');</script>";  ?>
<?php if(isset($message_email))  echo "<script>alert('".$message_email."');</script>";  ?>
</body>
</html>
